How to obtain the value of a custom contributor field via a RTC participant plugin?
Hello,
I have a work item with a custom field (of type Contributor) called:
Requested By:
If for example, this field is set to "John Smith", how can I get the name of the user which is set in the work item via a RTC participant plugin?
/**
* Gets the value of a Work Item (Contributor (User)) attribute.
*/
public String getAttributeValue_Contributor(String attributeID) throws TeamRepositoryException
{
String returnValue = "";
IAttribute attribute = workItemServer.findAttribute(workItem.getProjectArea(), attributeID, monitor);
Object value = workItem.getValue(attribute);
// ???
returnValue = contributor.getName();
return returnValue;
}
Thanks!
Accepted answer
Thanks Ralph.
I have it working now :-)
I have it working now :-)
import com.ibm.team.repository.common.IContributor; import com.ibm.team.repository.common.IContributorHandle; import com.ibm.team.repository.service.IRepositoryItemService;
----------------------------------------------------------- IRepositoryItemService itemService = getService(IRepositoryItemService.class); -----------------------------------------------------------
/** * Gets the value of a Work Item (Contributor (User)) attribute.
*
*/
public String getAttributeValue_Contributor(String attributeID) throws TeamRepositoryException {
String returnValue = "";
IAttribute attribute = workItemServer.findAttribute(workItem.getProjectArea(), attributeID, monitor);
IContributorHandle contributorHandle = (IContributorHandle) workItem.getValue(attribute); IContributor contributor = (IContributor) itemService.fetchItem(contributorHandle, null);
returnValue = contributor.getName();
return returnValue; }
One other answer
Do a getValue()
Test if the instance of the object is an IContributorHandle, cast to the IContributorHandle, resolve the contributor from the handle. See https://rsjazz.wordpress.com/2014/05/26/only-owner-can-close-workitem-advisor/
This is true for almost all the values. You have to always cast the data and it is easy enough to look at what it is in a debugging session. Also see https://rsjazz.wordpress.com/2013/03/20/understanding-and-using-the-rtc-java-client-api/
Test if the instance of the object is an IContributorHandle, cast to the IContributorHandle, resolve the contributor from the handle. See https://rsjazz.wordpress.com/2014/05/26/only-owner-can-close-workitem-advisor/
This is true for almost all the values. You have to always cast the data and it is easy enough to look at what it is in a debugging session. Also see https://rsjazz.wordpress.com/2013/03/20/understanding-and-using-the-rtc-java-client-api/